<?php
/*
 * @Author: your name
 * @Date: 2022-01-20 16:26:40
 * @LastEditTime: 2022-02-15 12:37:21
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /nlog/app/Models/crm_model/CrmLinkman.php
 */

namespace App\Models\crm_model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class CrmSituation extends Model
{
    use HasFactory;
    static string $tableName = 'crm_situation';
    
    public static function situationInsertUpdatedStr($keyStr,$valStr,$updateStr){
        return   DB::update("INSERT INTO ".self::$tableName." ( ".$keyStr.",update_time,create_time) VALUES ( ".$valStr.",NOW(),NOW() ) ON DUPLICATE KEY UPDATE ".$updateStr.",update_time = now() ");

    }

    public static function situationInsert($formData){
        return DB::table(self::$tableName)->insertGetId($formData);
    }

    public static function situationUpdate($formData,$id){
        return DB::table(self::$tableName)->where(['id'=>$id])->update($formData);
    }

    public static function list($whereStr,$limitStr){
        return DB::select(" SELECT * FROM ".self::$tableName." WHERE `delete_time` is null  ".$whereStr." ORDER BY `id` DESC ".$limitStr);
    }

    public static function count($whereStr){
        return DB::select(" SELECT COUNT(*) as `count` FROM ".self::$tableName." WHERE `delete_time` is null  ".$whereStr);

    }



   
   
   
}

